﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise {
    import Engine.Managers.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import Classes.sim.*;
    import __AS3__.vec.*;
    import Display.*;
    import Display.MarketUI.*;
    import GameMode.*;
    import Modules.stats.data.*;
    import Classes.orders.*;
    import Classes.inventory.*;
    import Modules.franchise.data.*;
    import Modules.stats.*;
    import Modules.stats.types.*;
    import com.adobe.utils.*;
    import Modules.franchise.transactions.*;

    public class FranchiseManager implements IStatsTarget {

        private static const BASE_SIGNATURE_REQUIREMENT:int = 3;
        private static const CITY_SIGNATURE_REQUIREMENT:int = 5;
        private static const MAX_SIGNATURE_REQUIREMENT:int = 10;
        public static const CITY_ITEM_NAME:String = "cityName";

        private var m_franchiseData:FranchiseData;
        private var m_model:FranchiseDataModel;
        private var m_worldOwnerModel:FranchiseDataModel;
        private var m_placementMode:Boolean = false;

        public function get placementMode():Boolean{
            return (this.m_placementMode);
        }
        public function isFranchiseItem(_arg1:Item):Boolean{
            var _local2:Boolean;
            if ((((_arg1.type == "business")) && (!((Global.world.ownerId == Global.player.uid))))){
                _local2 = true;
            };
            return (_local2);
        }
        public function set placementMode(_arg1:Boolean):void{
            this.m_placementMode = _arg1;
            if (!this.m_placementMode){
                Global.guide.removeMask();
                if (!Global.isTransitioningWorld){
                    Global.world.addGameMode(new GMVisit(Global.world.ownerId), true);
                };
                UI.displayCatalog("close");
            };
        }
        public function get eligibleFranchises():Array{
            var _local1:Array = Global.gameSettings.getPlaceableItems("business");
            return (_local1.filter(this.isFranchisable));
        }
        public function get model():FranchiseDataModel{
            return (this.m_model);
        }
        public function get worldOwnerModel():FranchiseDataModel{
            var _local1:FranchiseDataModel;
            if (Global.world.ownerId == Global.player.uid){
                _local1 = this.m_model;
            } else {
                _local1 = this.m_worldOwnerModel;
            };
            return (_local1);
        }
        public function get nextFranchiseUnlock():Number{
            return ((Math.ceil(((Global.player.level + 1) / 10)) * 10));
        }
        public function isFranchisable(_arg1:Item, ... _args):Boolean{
            var _local3 = !((_arg1.className == "LotSite"));
            var _local4:Boolean = BuyLogic.canFranchise(_arg1);
            var _local5:Boolean = BuyLogic.franchiseCountLevelCheck(_arg1);
            var _local6:Boolean = BuyLogic.hasFranchiseCheck(_arg1);
            return (((((((_local3) && (_local4))) && (_local5))) && (_local6)));
        }
        public function isFranchiseLocked():Boolean{
            var _local1:int = this.getFranchiseCount();
            var _local2:int = this.getFranchiseCap();
            return ((_local1 >= _local2));
        }
        public function loadObject(_arg1:Object):void{
            var _local3:Object;
            var _local4:OwnedFranchiseData;
            var _local2:Vector.<OwnedFranchiseData> = new Vector.<OwnedFranchiseData>();
            for each (_local3 in _arg1) {
                _local4 = OwnedFranchiseData.loadObject(_local3);
                if (_local4.franchiseType != "history"){
                    _local2.push(_local4);
                };
            };
            this.m_franchiseData = new FranchiseData(_local2, null);
            this.m_model = new FranchiseDataModel(Global.player.uid, Global.player.firstName, this.m_franchiseData);
        }
        public function getMapOwnerFirstName(_arg1:String):String{
            var _local4:String;
            var _local2:String;
            var _local3:Player = Global.player.findFriendById(_arg1);
            if (_local3 != null){
                _local2 = _local3.firstName;
            } else {
                _local2 = ZLoc.t("Dialogs", "DefaultFriendName");
            };
            return (_local2);
        }
        public function loadWorldObject(_arg1:Object, _arg2:String):void{
            var _local3:Vector.<OwnedFranchiseData>;
            var _local4:FranchiseData;
            var _local5:Object;
            var _local6:OwnedFranchiseData;
            if (_arg2 == GameWorld.CITY_SAM_OWNER_ID){
                _local3 = this.getCitySamFranchiseData();
            } else {
                _local3 = new Vector.<OwnedFranchiseData>();
                for each (_local5 in _arg1) {
                    _local6 = OwnedFranchiseData.loadObject(_local5);
                    if (_local6.franchiseType != "history"){
                        _local3.push(_local6);
                    };
                };
            };
            _local4 = new FranchiseData(_local3, null);
            this.m_worldOwnerModel = new FranchiseDataModel(_arg2, Global.player.getFriendFirstName(_arg2), _local4);
        }
        private function getCitySamFranchiseData():Vector.<OwnedFranchiseData>{
            var _local3:Item;
            var _local4:String;
            var _local1:Vector.<OwnedFranchiseData> = new Vector.<OwnedFranchiseData>();
            var _local2:Array = Global.gameSettings.getItemsByType("business");
            for each (_local3 in _local2) {
                _local4 = _local3.name;
                _local1.push(OwnedFranchiseData.loadCitySamObject(_local4));
            };
            return (_local1);
        }
        public function collectDailyBonus(_arg1:String):void{
            var _local2:OwnedFranchiseData = this.m_model.getOwnedFranchise(_arg1);
            _local2.dailyBonusAvailable = false;
            _local2.dailyBonusLastCollect = (GlobalEngine.getTimer() / 1000);
        }
        public function collect(_arg1:String, _arg2:String):void{
            var _local3:OwnedFranchiseData = this.m_model.getOwnedFranchise(_arg1);
            var _local4:FranchiseExpansionData = _local3.locations[_arg2];
            var _local5:String = this.m_model.getHeadquartersType(_local4.franchiseType);
            _local4.timeLastSupplied = (GlobalEngine.getTimer() / 1000);
            if (_local4.locationUid != "-1"){
                StatsManager.social(StatsCounterType.FRANCHISES, _local4.locationUid, "sent_sale", _local4.franchiseType);
            };
        }
        public function getFranchiseCountByLocation(_arg1:String):int{
            var _local2:Vector.<FranchiseExpansionData> = Global.franchiseManager.model.getFranchisesByLocation(_arg1);
            return (_local2.length);
        }
        public function getNewHeadquarterTypes():Vector.<String>{
            var _local3:String;
            var _local5:OwnedFranchiseData;
            var _local6:Dictionary;
            var _local7:Array;
            var _local8:int;
            var _local9:Boolean;
            var _local10:String;
            var _local11:int;
            var _local12:Array;
            var _local13:MapResource;
            var _local14:Array;
            var _local15:ConstructionSite;
            var _local16:int;
            var _local1:Vector.<String> = new Vector.<String>();
            var _local2:Array = [];
            var _local4:Vector.<OwnedFranchiseData> = this.m_model.getOwnedFranchises();
            for each (_local5 in _local4) {
                _local6 = _local5.locations;
                _local7 = DictionaryUtil.getKeys(_local6);
                _local8 = _local7.length;
                if (_local8 > 0){
                    _local9 = Boolean((((_local8 == 1)) && (!((_local6[GameWorld.CITY_SAM_OWNER_ID] == null)))));
                    if (!_local9){
                        _local10 = _local5.franchiseType;
                        _local3 = this.m_model.getHeadquartersType(_local10);
                        if (_local3){
                            _local11 = Global.player.inventory.getItemCountByName(_local3);
                            if (_local11 <= 0){
                                _local2[_local2.length] = _local3;
                            };
                        };
                    };
                };
            };
            if ((((_local2.length > 0)) && (!(Global.isVisiting())))){
                _local12 = Global.world.getObjectsByNames(_local2);
                for each (_local13 in _local12) {
                    _local3 = _local13.getItem().name;
                    _local16 = _local2.indexOf(_local3);
                    if (_local16 >= 0){
                        _local2.splice(_local16, 1);
                    };
                };
                _local14 = Global.world.getObjectsByClass(ConstructionSite);
                for each (_local15 in _local14) {
                    _local3 = _local15.targetName;
                    _local16 = _local2.indexOf(_local3);
                    if (_local16 >= 0){
                        _local2.splice(_local16, 1);
                    };
                };
                for each (_local3 in _local2) {
                    _local1[_local1.length] = _local3;
                };
            };
            return (_local1);
        }
        public function getHeadquartersHeight(_arg1:String, _arg2:String=null):Number{
            var _local4:FranchiseDataModel;
            var _local3:String = this.getFranchiseTypeFromHeadquarters(_arg1);
            if ((((_arg2 == null)) || ((_arg2 == Global.player.uid)))){
                _local4 = this.m_model;
            } else {
                if (_arg2 == Global.world.ownerId){
                    _local4 = this.m_worldOwnerModel;
                };
            };
            var _local5:Number = _local4.getFranchiseCountByType(_local3);
            var _local6:Number = (_local5 * this.getHeadquartersHeightPerExpansion(_arg1));
            var _local7:Number = this.getHeadquartersHeightLimit(_arg1);
            var _local8:Number = _local6;
            if (_local7 >= 0){
                _local8 = Math.min(_local8, _local7);
            };
            return (_local8);
        }
        public function getFranchiseTypeFromHeadquarters(_arg1:String):String{
            return (Global.gameSettings.getFranchiseTypeFromHeadquarters(_arg1));
        }
        public function getBusinessFromType(_arg1:String):Business{
            var _local4:Business;
            var _local2:Business;
            var _local3:Array = Global.world.getObjectsByClass(Business);
            for each (_local4 in _local3) {
                if (_local4.franchiseType == _arg1){
                    _local2 = _local4;
                    break;
                };
            };
            return (_local2);
        }
        public function getPendingFranchiseFromTypeAndOwner(_arg1:String, _arg2:String):Business{
            var _local5:Business;
            var _local3:Business;
            var _local4:Array = Global.world.getObjectsByClass(Business);
            for each (_local5 in _local4) {
                if ((((_local5.franchiseType == _arg1)) && ((_local5.getBusinessOwner() == _arg2)))){
                    _local3 = _local5;
                    break;
                };
            };
            return (_local3);
        }
        public function getDataModel(_arg1:String):FranchiseDataModel{
            var _local2:FranchiseDataModel;
            if (((this.m_model) && ((this.m_model.ownerUid == _arg1)))){
                _local2 = this.m_model;
            } else {
                if (((this.m_worldOwnerModel) && ((this.m_worldOwnerModel.ownerUid == _arg1)))){
                    _local2 = this.m_worldOwnerModel;
                };
            };
            return (_local2);
        }
        public function getFranchiseName(_arg1:String, _arg2:String):String{
            var _local3:String;
            if (_arg2 == Global.player.uid){
                _local3 = this.m_model.getFranchiseName(_arg1);
            } else {
                if (_arg2 == Global.world.ownerId){
                    _local3 = this.m_worldOwnerModel.getFranchiseName(_arg1);
                };
            };
            return (_local3);
        }
        public function getPendingName(_arg1:String, _arg2:String):String{
            var _local3:String;
            if (_arg1 == CITY_ITEM_NAME){
                _local3 = Global.player.pendingCityName;
            } else {
                if (_arg2 == Global.player.uid){
                    _local3 = this.m_model.getPendingName(_arg1);
                } else {
                    if (_arg2 == Global.world.ownerId){
                        _local3 = this.m_worldOwnerModel.getPendingName(_arg1);
                    };
                };
            };
            return (_local3);
        }
        public function getHeadquartersFriendlyName(_arg1:String):String{
            var _local2:String = Global.franchiseManager.getFranchiseTypeFromHeadquarters(_arg1);
            var _local3:String = Global.franchiseManager.worldOwnerModel.getFranchiseName(_local2);
            var _local4:String = ZLoc.t("Items", "headquarters", {item:_local3});
            return (_local4);
        }
        public function getFranchise(_arg1:String):OwnedFranchiseData{
            var _local4:OwnedFranchiseData;
            var _local2:OwnedFranchiseData;
            var _local3:Vector.<OwnedFranchiseData> = this.getAllFranchises();
            for each (_local4 in _local3) {
                if (_local4.franchiseType == _arg1){
                    _local2 = _local4;
                    break;
                };
            };
            return (_local2);
        }
        public function getAllFranchises():Vector.<OwnedFranchiseData>{
            var _local1:Vector.<OwnedFranchiseData> = this.m_model.getOwnedFranchises();
            var _local2:Vector.<OwnedFranchiseData> = this.getPendingSentFranchiseOrders();
            var _local3:Vector.<OwnedFranchiseData> = this.mergeOwnedFranchises(_local1, _local2);
            return (_local3);
        }
        public function getFranchiseCount():Number{
            var _local3:OwnedFranchiseData;
            var _local1:Number = 0;
            var _local2:Vector.<OwnedFranchiseData> = this.getAllFranchises();
            for each (_local3 in _local2) {
                if (_local3.getLocationCount() > 0){
                    _local1++;
                };
            };
            return (_local1);
        }
        public function getAllFranchisesLocationCount():Number{
            var _local3:OwnedFranchiseData;
            var _local1:Number = 0;
            var _local2:Vector.<OwnedFranchiseData> = this.getAllFranchises();
            for each (_local3 in _local2) {
                _local1 = (_local1 + _local3.getLocationCount());
            };
            return (_local1);
        }
        public function getAllFranchiseAcceptedLocationsCount():Number{
            var _local3:OwnedFranchiseData;
            var _local4:FranchiseExpansionData;
            var _local1:Number = 0;
            var _local2:Vector.<OwnedFranchiseData> = this.getAllFranchises();
            for each (_local3 in _local2) {
                for each (_local4 in _local3.locations) {
                    if (_local4.isOpen()){
                        _local1++;
                    };
                };
            };
            return (_local1);
        }
        public function getFranchiseAcceptedLocationsCount(_arg1:String):Number{
            var _local4:FranchiseExpansionData;
            var _local2:Number = 0;
            var _local3:OwnedFranchiseData = this.getFranchise(_arg1);
            for each (_local4 in _local3.locations) {
                if (_local4.isOpen()){
                    _local2++;
                };
            };
            return (_local2);
        }
        public function getFranchiseCap():Number{
            return ((Math.floor((Global.player.level / 10)) + 1));
        }
        public function isPendingFranchise(_arg1:String):Boolean{
            var _local3:FranchiseExpansionData;
            var _local2:OwnedFranchiseData = this.getFranchise(_arg1);
            for each (_local3 in _local2.locations) {
                if (_local3.isOpen()){
                    return (false);
                };
            };
            return (true);
        }
        public function mapElapsedToCompleteness(_arg1:Number):Number{
            var _local5:Number;
            var _local2:Dictionary = new Dictionary();
            _local2[0] = 100;
            _local2[72] = 50;
            _local2[96] = 0;
            var _local3:Number = _local2[0];
            var _local4:Array = DictionaryUtil.getKeys(_local2);
            _local4.reverse();
            for each (_local5 in _local4) {
                if (_arg1 >= _local5){
                    _local3 = _local2[_local5];
                    break;
                };
            };
            return (_local3);
        }
        public function getAllFranchisesByType(_arg1:String):Vector.<FranchiseExpansionData>{
            var _local4:FranchiseExpansionData;
            var _local2:Vector.<FranchiseExpansionData> = this.m_model.getFranchisesByType(_arg1).slice();
            var _local3:Vector.<FranchiseExpansionData> = this.getPendingSentFranchiseOrderLocationsByType(_arg1);
            for each (_local4 in _local3) {
                _local2.push(_local4);
            };
            return (_local2);
        }
        public function getRequiredSignatures(_arg1:String):int{
            var _local3:OwnedFranchiseData;
            var _local2:int;
            if (_arg1 == CITY_ITEM_NAME){
                _local2 = CITY_SIGNATURE_REQUIREMENT;
            } else {
                _local2 = BASE_SIGNATURE_REQUIREMENT;
                _local3 = this.getFranchise(_arg1);
                if (_local3){
                    _local2 = (_local2 + _local3.getLocationCount());
                };
            };
            if (_local2 > MAX_SIGNATURE_REQUIREMENT){
                _local2 = MAX_SIGNATURE_REQUIREMENT;
            };
            return (_local2);
        }
        public function getSignatureCount(_arg1:String):int{
            return (Global.player.requestInventory.getItemCount(RequestItemType.SIGNATURE, _arg1));
        }
        public function isSignatureComplete(_arg1:String):Boolean{
            var _local3:OwnedFranchiseData;
            var _local2:String;
            if (_arg1 == CITY_ITEM_NAME){
                _local2 = Global.player.pendingCityName;
            } else {
                _local3 = this.getFranchise(_arg1);
                if (_local3 != null){
                    _local2 = _local3.pendingName;
                };
            };
            return (((!((_local2 == null))) && ((this.getSignatureCount(_arg1) >= this.getRequiredSignatures(_arg1)))));
        }
        public function getCompletedSignatureCount():int{
            var _local3:OwnedFranchiseData;
            var _local1:int;
            var _local2:Vector.<OwnedFranchiseData> = this.getAllFranchises();
            for each (_local3 in _local2) {
                if (this.isSignatureComplete(_local3.franchiseType)){
                    _local1++;
                };
            };
            if (this.isSignatureComplete(CITY_ITEM_NAME)){
                _local1++;
            };
            return (_local1);
        }
        public function getStatsCounterObject():Vector.<StatsCountData>{
            var _local7:Business;
            var _local8:int;
            var _local9:Vector.<String>;
            var _local10:String;
            var _local11:int;
            var _local12:String;
            var _local13:int;
            var _local14:Array;
            var _local15:Headquarter;
            var _local16:int;
            var _local17:String;
            var _local18:OwnedFranchiseData;
            var _local19:String;
            var _local20:int;
            var _local21:int;
            var _local22:int;
            var _local23:Vector.<FranchiseExpansionData>;
            var _local24:FranchiseExpansionData;
            var _local1:Vector.<StatsCountData> = new Vector.<StatsCountData>();
            var _local2:LotManager = Global.world.citySim.lotManager;
            _local1.push(new StatsCountData(new StatsOntology("num_open_lots"), _local2.lotSites.length));
            var _local3:int = this.getPendingReceivedFranchiseOrders().length;
            _local1.push(new StatsCountData(new StatsOntology("num_pending_franchises_on_user_map"), _local3));
            var _local4:int = this.getPendingSentFranchiseOrders().length;
            _local1.push(new StatsCountData(new StatsOntology("num_pending_franchises_on_friend_map"), _local4));
            var _local5:Array = Global.world.getObjectsByClass(Business);
            var _local6:int;
            for each (_local7 in _local5) {
                if (_local7.isFranchise()){
                    _local6++;
                };
            };
            _local1.push(new StatsCountData(new StatsOntology("num_running_franchises_on_user_map"), _local6));
            _local8 = 0;
            _local9 = this.m_model.getFranchiseTypes();
            for each (_local10 in _local9) {
                _local18 = this.m_model.getOwnedFranchise(_local10);
                _local8 = (_local8 + _local18.getLocationCount());
            };
            _local1.push(new StatsCountData(new StatsOntology("num_running_franchises_on_friend_map"), _local8));
            _local11 = 0;
            for each (_local12 in _local9) {
                _local19 = this.m_model.getHeadquartersType(_local12);
                _local20 = Global.player.inventory.getItemCountByName(_local19);
                if (_local20 > 0){
                    _local21 = this.getHeadquartersHeight(_local19);
                    _local1.push(new StatsCountData(new StatsOntology("franchise_HQ", "HQ_unplaced", _local21.toString()), _local20));
                };
            };
            _local13 = 0;
            _local14 = Global.world.getObjectsByClass(Headquarter);
            for each (_local15 in _local14) {
                _local22 = _local15.floorCount;
                _local1.push(new StatsCountData(new StatsOntology("franchise_HQ", "HQ_placed", _local22.toString())));
            };
            _local16 = 0;
            for each (_local17 in _local9) {
                _local23 = this.m_model.getFranchisesByType(_local17);
                for each (_local24 in _local23) {
                    if (_local24.commodityLeft > 0){
                        _local16++;
                    };
                };
            };
            _local1.push(new StatsCountData(new StatsOntology("pending_sent_sales"), _local16));
            return (_local1);
        }
        private function mergeOwnedFranchises(_arg1:Vector.<OwnedFranchiseData>, _arg2:Vector.<OwnedFranchiseData>):Vector.<OwnedFranchiseData>{
            var _local4:OwnedFranchiseData;
            var _local5:OwnedFranchiseData;
            var _local6:OwnedFranchiseData;
            var _local7:OwnedFranchiseData;
            var _local3:Vector.<OwnedFranchiseData> = new Vector.<OwnedFranchiseData>();
            for each (_local4 in _arg1) {
                _local3.push(_local4.clone());
            };
            for each (_local5 in _arg2) {
                _local6 = null;
                for each (_local7 in _local3) {
                    if (_local7.franchiseType == _local5.franchiseType){
                        _local6 = _local7;
                        _local6.merge(_local5);
                        break;
                    };
                };
                if (!_local6){
                    _local3.push(_local5);
                };
            };
            return (_local3);
        }
        private function getPendingSentFranchise(_arg1:String):OwnedFranchiseData{
            return (this.getPendingFranchise(_arg1, this.getPendingSentFranchiseOrders()));
        }
        private function getPendingReceivedFranchise(_arg1:String):OwnedFranchiseData{
            return (this.getPendingFranchise(_arg1, this.getPendingReceivedFranchiseOrders()));
        }
        private function getPendingFranchise(_arg1:String, _arg2:Vector.<OwnedFranchiseData>):OwnedFranchiseData{
            var _local4:OwnedFranchiseData;
            var _local3:OwnedFranchiseData;
            for each (_local4 in _arg2) {
                if (_local4.franchiseType == _arg1){
                    _local3 = _local4;
                    break;
                };
            };
            return (_local3);
        }
        public function getPendingSentFranchiseOrderForNeighbor(_arg1:String):LotOrder{
            var _local3:LotOrder;
            var _local2:Array = Global.world.citySim.lotManager.sentPendingOrders;
            for each (_local3 in _local2) {
                if (_local3.getRecipientID() == _arg1){
                    return (_local3);
                };
            };
            return (null);
        }
        public function getPendingSentFranchiseOrders():Vector.<OwnedFranchiseData>{
            var _local3:String;
            var _local4:Vector.<LotOrder>;
            var _local5:OwnedFranchiseData;
            var _local1:Vector.<OwnedFranchiseData> = new Vector.<OwnedFranchiseData>();
            var _local2:Vector.<String> = this.getPendingSentFranchiseOrderTypes();
            for each (_local3 in _local2) {
                _local4 = this.getPendingSentFranchiseOrdersByType(_local3);
                _local5 = OwnedFranchiseData.loadPendingObject(_local4);
                _local1.push(_local5);
            };
            return (_local1);
        }
        public function getPendingReceivedFranchiseOrders():Vector.<OwnedFranchiseData>{
            var _local3:String;
            var _local4:Vector.<LotOrder>;
            var _local5:OwnedFranchiseData;
            var _local1:Vector.<OwnedFranchiseData> = new Vector.<OwnedFranchiseData>();
            var _local2:Vector.<String> = this.getPendingReceivedFranchiseOrderTypes();
            for each (_local3 in _local2) {
                _local4 = this.getPendingReceivedFranchiseOrdersByType(_local3);
                _local5 = OwnedFranchiseData.loadPendingObject(_local4);
                _local1.push(_local5);
            };
            return (_local1);
        }
        private function getPendingSentFranchiseOrderTypes():Vector.<String>{
            return (this.getPendingFranchiseOrderTypes(Global.world.citySim.lotManager.sentPendingOrders));
        }
        private function getPendingReceivedFranchiseOrderTypes():Vector.<String>{
            return (this.getPendingFranchiseOrderTypes(Global.world.citySim.lotManager.receivedPendingOrders));
        }
        private function getPendingFranchiseOrderTypes(_arg1:Array):Vector.<String>{
            var _local3:LotOrder;
            var _local2:Vector.<String> = new Vector.<String>();
            for each (_local3 in _arg1) {
                if (((this.isFranchiseOrder(_local3)) && ((_local2.indexOf(_local3.getResourceType()) < 0)))){
                    _local2.push(_local3.getResourceType());
                };
            };
            return (_local2);
        }
        private function getPendingSentFranchiseOrderLocationsByType(_arg1:String):Vector.<FranchiseExpansionData>{
            return (this.getPendingFranchiseOrderLocationsByType(_arg1, this.getPendingSentFranchiseOrdersByType(_arg1)));
        }
        private function getPendingReceivedFranchiseOrderLocationsByType(_arg1:String):Vector.<FranchiseExpansionData>{
            return (this.getPendingFranchiseOrderLocationsByType(_arg1, this.getPendingReceivedFranchiseOrdersByType(_arg1)));
        }
        private function getPendingFranchiseOrderLocationsByType(_arg1:String, _arg2:Vector.<LotOrder>):Vector.<FranchiseExpansionData>{
            var _local4:LotOrder;
            var _local3:Vector.<FranchiseExpansionData> = new Vector.<FranchiseExpansionData>();
            for each (_local4 in _arg2) {
                _local3.push(FranchiseExpansionData.loadPendingObject(_local4));
            };
            return (_local3);
        }
        private function getPendingSentFranchiseOrdersByType(_arg1:String):Vector.<LotOrder>{
            return (this.getPendingFranchiseOrdersByType(_arg1, Global.world.citySim.lotManager.sentPendingOrders));
        }
        private function getPendingReceivedFranchiseOrdersByType(_arg1:String):Vector.<LotOrder>{
            return (this.getPendingFranchiseOrdersByType(_arg1, Global.world.citySim.lotManager.receivedPendingOrders));
        }
        private function getPendingFranchiseOrdersByType(_arg1:String, _arg2:Array):Vector.<LotOrder>{
            var _local4:LotOrder;
            var _local3:Vector.<LotOrder> = new Vector.<LotOrder>();
            for each (_local4 in _arg2) {
                if (((this.isFranchiseOrder(_local4)) && ((_local4.getResourceType() == _arg1)))){
                    _local3.push(_local4);
                };
            };
            return (_local3);
        }
        public function isFranchiseOrder(_arg1:LotOrder):Boolean{
            var _local2:Item = Global.gameSettings.getItemByName(_arg1.getResourceType());
            return (((_local2) && ((_local2.type == "business"))));
        }
        private function getHeadquartersHeightLimit(_arg1:String):Number{
            var _local2:Number = 0;
            var _local3:Item = Global.gameSettings.getItemByName(_arg1);
            if (_local3){
                _local2 = _local3.heightLimit;
            };
            return (_local2);
        }
        private function getHeadquartersHeightPerExpansion(_arg1:String):Number{
            return (Global.gameSettings.getInt("hqFloorMultiplier"));
        }
        private function verifyHeadquartersUpdate(_arg1:FranchiseExpansionData):Boolean{
            return (this.isFirstCollect(_arg1));
        }
        private function verifyHeadquartersGrant(_arg1:FranchiseExpansionData, _arg2:String):Boolean{
            var _local4:Number;
            var _local3:Boolean;
            if (this.verifyHeadquartersUpdate(_arg1)){
                _local4 = this.getCollectCount(this.m_model, _arg1.franchiseType);
                if (_local4 == 0){
                    _local3 = true;
                };
            };
            return (_local3);
        }
        private function getCollectCount(_arg1:FranchiseDataModel, _arg2:String):Number{
            var _local5:FranchiseExpansionData;
            var _local3:Number = 0;
            var _local4:Vector.<FranchiseExpansionData> = _arg1.getFranchisesByType(_arg2);
            for each (_local5 in _local4) {
                if (!this.isFirstCollect(_local5)){
                    _local3++;
                };
            };
            return (_local3);
        }
        private function isFirstCollect(_arg1:FranchiseExpansionData):Boolean{
            return (((_arg1) && (!(_arg1.timeLastSupplied))));
        }
        public function grantHeadquarters(_arg1:String, _arg2:Boolean=true):void{
            var _local3:String = this.getFranchiseTypeFromHeadquarters(_arg1);
            Global.player.inventory.addItems(_arg1, 1, true);
            if (_arg2){
                this.serverGrantHeadquarters(_local3);
            };
        }
        private function serverGrantHeadquarters(_arg1:String):void{
            GameTransactionManager.addTransaction(new TGrantHeadquarters(_arg1));
        }
        private function createHeadquartersGrowDialog():Dialog{
            var _local1:Dialog;
            var _local2:String = ZLoc.t("Dialogs", "NewHeadquartersTitle");
            var _local3:String = ZLoc.t("Dialogs", "GrowHeadquartersMessage");
            _local1 = new GenericDialog(_local3, _local2);
            return (_local1);
        }
        private function createHeadquartersMaxDialog():Dialog{
            var _local1:Dialog;
            var _local2:String = ZLoc.t("Dialogs", "NewHeadquartersTitle");
            var _local3:String = ZLoc.t("Dialogs", "MaxHeadquartersMessage");
            _local1 = new GenericDialog(_local3, _local2);
            return (_local1);
        }
        public function headquarterFloorBuildCompleted(_arg1:String):void{
            this.updateHeadquarters(_arg1);
        }
        private function updateHeadquarters(_arg1:String):void{
            var _local4:Headquarter;
            var _local5:String;
            var _local6:Business;
            var _local7:Number;
            var _local2:Item = Global.gameSettings.getItemByName(_arg1);
            if (_local2){
                _local5 = Global.franchiseManager.getFranchiseTypeFromHeadquarters(_arg1);
                _local6 = Global.franchiseManager.getBusinessFromType(_local5);
                if (this.getHeadquartersHeight(_arg1) < _local2.heightLimit){
                    _local7 = this.getHeadquartersHeight(_arg1);
                    if (_local7 >= _local2.heightLimit){
                        FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_GROWHQ_LAST, _local5, "", null, 0, _local6);
                    } else {
                        FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_GROWHQ_NEXT, _local5, "", null, 0, _local6);
                    };
                };
            };
            var _local3:Array = Global.world.getObjectsByNames([_arg1]);
            for each (_local4 in _local3) {
                _local4.drawContent();
            };
        }

    }
}//package Modules.franchise 
